package com.zb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjSysSetOverall;
import com.zb.mapper.ZjSysSetOverallMapper;
import com.zb.service.CustomerAuthorDefaultDataService;
import com.zb.service.GoodsSetService;
import com.zb.service.ZjSysSetOverallService;
import com.zb.vo.SysSetOverallVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;

/**
 * <p>
 * 系统全局设置表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-07-25
 */
@Service
public class ZjSysSetOverallServiceImpl extends ServiceImpl<ZjSysSetOverallMapper, ZjSysSetOverall> implements ZjSysSetOverallService {
    @Resource
    private GoodsSetService goodsSetService;
    @Resource
    private CustomerAuthorDefaultDataService customerAuthorDefaultDataService;

    // 初始化 或 恢复初始化系统全局设置
    @Override
    public void initOrRestoreDefaultSysSetOverall(Long custAccId) {
        ZjSysSetOverall overall = new ZjSysSetOverall();
        overall.setId(custAccId);
        overall.setAddressLevel(2);
        overall.setWebsiteName("");
        overall.setLogo("");
        overall.setReduceLogo("");
        overall.setMobileServiceLogo("");
        overall.setStoreLogo("");
        this.saveOrUpdate(overall);
    }

    // 初始化默认值
    @Override
    public void initDefaultValue(Long custAccId) {
        initOrRestoreDefaultSysSetOverall(custAccId);
        goodsSetService.saveDefaultValue(custAccId);
        customerAuthorDefaultDataService.saveCustomerAuthor(custAccId);
    }

    // 获取系统全局设置
    @Override
    public SysSetOverallVo getSysSetOverall(Long custAccId) {
        ZjSysSetOverall overall = this.getById(custAccId);
        return SysSetOverallVo.beanToVo(overall);
    }

    // 更新系统全局设置
    @Override
    public void saveSysSetOverall(SysSetOverallVo overallVo) {
        ZjSysSetOverall overall = SysSetOverallVo.voToBean(overallVo);
        this.updateById(overall);
    }

    // 获取系统全局设置的地址库级别
    @Override
    public Integer getAddressLevel(Long custAccId) {
//        QueryWrapper<ZjSysSetOverall> wrapper = new QueryWrapper<>();
//        wrapper.select("address_level");
//        wrapper.eq("id", custAccId);
//        ZjSysSetOverall overall = this.getOne(wrapper);
        return 2;
    }

    // 获取PC端Logo
    @Override
    public Object getPcLog(Long custAccId) {
        ZjSysSetOverall overall = this.getById(custAccId);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("websiteName", overall.getWebsiteName());
        resultMap.put("logo", overall.getLogo());
        resultMap.put("reduceLogo", overall.getReduceLogo());
        return resultMap;
    }

}
